package router

import (
	"ginchat/docs"
	"ginchat/service"

	"github.com/gin-gonic/gin"

	swaggerFiles "github.com/swaggo/files"
	ginSwagger "github.com/swaggo/gin-swagger"
)

func Router() *gin.Engine {
	r := gin.Default()

	// swagger配置
	// programatically set swagger info
	docs.SwaggerInfo.Title = "GIN CHAT API"
	docs.SwaggerInfo.Description = "This is a study project"
	docs.SwaggerInfo.Version = "1.0"
	// docs.SwaggerInfo.Host = "petstore.swagger.io"
	// docs.SwaggerInfo.BasePath = "/v2"
	docs.SwaggerInfo.Schemes = []string{"http", "https"}

	// 配置静态资源
	r.Static("/asset", "asset/")
	r.LoadHTMLGlob("views/**/*")

	// 路由注册
	r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))

	// 首页
	r.GET("/index", service.GetIndex)
	r.GET("/", service.GetIndex)
	r.GET("/toChat", service.ToChat)
	r.GET("/chat", service.Chat)
	r.GET("/toRegister", service.ToRegister)
	r.POST("/searchFriends", service.SearchFriends)

	// 用户相关
	r.GET("/user/getUserList", service.GetUserList)
	r.POST("/user/createUser", service.CreateUser)
	r.POST("/user/deleteUser", service.DeleteUser)
	r.POST("/user/updateUser", service.UpdateUser)
	r.POST("/user/findUserByNameAndPwd", service.FindUserByNameAndPwd)
	r.POST("/user/find", service.FindByID)
	//添加好友
	r.POST("/contact/addfriend", service.AddFriend)

	//创建群
	r.POST("/contact/createCommunity", service.CreateCommunity)
	//群列表
	r.POST("/contact/loadcommunity", service.LoadCommunity)
	r.POST("/contact/joinGroup", service.JoinGroups)

	// 公共接口
	r.POST("/attach/upload", service.Upload)

	// websocket
	r.GET("user/sendMsg", service.SendMsg)
	r.GET("user/sendUserMsg", service.SendUserMsg)

	r.POST("/user/redisMsg", service.RedisMsg)
	// 返回实列
	return r
}
